package com.sunshine.student_register.database;

import android.content.Context;

import com.sunshine.student_register.database.register.RegisterDao;
import com.sunshine.student_register.database.register.RegisterEntity;
import com.sunshine.student_register.database.student.StudentDao;
import com.sunshine.student_register.database.student.StudentEntity;

import java.util.List;

/**
 * @author sunshine
 * @date 2020/5/30
 * 数据库操作类
 * 所有操作由这里实现
 * 具体操作见
 * @see com.sunshine.student_register.database.student.StudentDao
 * @see com.sunshine.student_register.database.register.RegisterDao
 */
public class StudentRegisterRepository {

    private StudentDao studentDao;
    private RegisterDao registerDao;

    public StudentRegisterRepository(Context context){
        StudentRegisterDatabase database = StudentRegisterDatabase.getDatabase(context);
        studentDao = database.getStudentDao();
        registerDao = database.getRegisterDao();
    }

    public void insertStudent(StudentEntity studentEntity){
        studentDao.insertStudent(studentEntity);
    }

    public List<StudentEntity> getAllStudent(){
        return studentDao.getAllStudent();
    }

    public StudentEntity getStudent(int id){
        return studentDao.getStudent(id);
    }

    public void updateStudent(StudentEntity studentEntity){
        studentDao.updateStudent(studentEntity);
    }

    public void deleteStudent(StudentEntity studentEntity){
        studentDao.deleteStudent(studentEntity);
    }

    public void deleteAllStudent(){
        studentDao.deleteAllStudent();
    }

    public void insertRegister(RegisterEntity registerEntity){
        registerDao.insertRegister(registerEntity);
    }

    public List<RegisterEntity> getAllRegister(){
        return registerDao.getAllRegister();
    }

    public List<RegisterEntity> getThisUserAllRegister(int userId) {
        return registerDao.getThisUserAllRegister(userId);
    }

    public void updateRegister(RegisterEntity registerEntity){
        registerDao.updateRegister(registerEntity);
    }

    public void deleteRegister(RegisterEntity registerEntity){
        registerDao.deleteRegister(registerEntity);
    }

    public void deleteAllRegister(){
        registerDao.deleteAllRegister();
    }
}
